﻿using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.SaleCategorys;
using System.Web;
namespace Ue.Qcdz.UI.Controls
{
    /// <summary>
    /// 商品分类
    /// </summary>
    public class SaleCategoryEdit : SkinnedEntityEdit<SaleCategory>
    {
        private TextBox tbxCategoryName;//栏目名称
        private TextBox tbxRemark;
        private TextBox tbxDisplayOrder;
        private RadioButtonList rBtnStatus;

        public SaleCategoryEdit()
        {
            this.ReturnUrl = Domain.SiteUrls.Instance.SaleCategory();
        }

        protected override SaleCategory Enttiy
        {
            get
            {
                SaleCategory model = SaleCategoryService.GetSaleCategory(this.EntityKey);

                if (model == null)
                {
                    model = new SaleCategory(this.EntityKey);
                    model.Shop = Domain.SiteContext.GetSiteContext().Shop;
                }
                if (tbxCategoryName != null)
                    model.Name = tbxCategoryName.GetValue<string>();
                if (tbxRemark != null)
                    model.Remark = tbxRemark.GetValue<string>();
                if (tbxDisplayOrder != null)
                    model.DisplayOrder = tbxDisplayOrder.GetValue<int>();
                if (rBtnStatus != null)
                    model.Status = rBtnStatus.SelectedValue == "1" ? 1 : 0;

                return model;
            }
            set
            {
                if (value == null)
                    return;

                tbxCategoryName.SetValue(value.Name);
                tbxRemark.SetValue(value.Remark);
                tbxDisplayOrder.SetValue(value.DisplayOrder);

                rBtnStatus.SelectedIndex = -1;
                rBtnStatus.Items.FindByValue(value.Status.ToString()).Selected = true;

            }
        }

        protected override void InitSkin(System.Web.UI.Control skin)
        {
            tbxCategoryName = skin.FindControl<TextBox>("tbxCategoryName");
            tbxRemark = skin.FindControl<TextBox>("tbxRemark");
            tbxDisplayOrder = skin.FindControl<TextBox>("tbxDisplayOrder");
            rBtnStatus = skin.FindControl<RadioButtonList>("rBtnStatus");
        }

        protected override string GetSkinFileName()
        {
            return "~/Themes/zh-cn/Skins/SaleCategorys/SaleCategoryEdit.ascx";
        }

        
    }
}
